package com.txts.road.admin.raceSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.raceSys.domain.RaceSys;
import com.txts.road.admin.raceSys.service.IRaceSysService;
import com.txts.road.admin.vehicleSys.domain.raceVehicle;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 赛段信息Controller
 *
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/RaceSys/raceInfo")
@Tag(name = "赛段信息接口")
public class RaceSysController extends BaseController {
    @Resource
    private IRaceSysService raceSysService;

    /**
     * 查询赛段信息列表
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:list')")
    @GetMapping("/list")
    @Operation(summary = "查询赛段信息列表", description = "根据条件查询赛段信息列表")
    public ResponseDTO<PageResult<RaceSys>> list(RaceSys raceSys) {
        startPage();
        List<RaceSys> list = raceSysService.selectRaceSysList(raceSys);
        return getDataTable(list);
    }

    /**
     * 导出赛段信息列表
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:export')")
    @Log(title = "赛段信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出赛段信息列表", description = "导出赛段信息列表")
    public void export(HttpServletResponse response, RaceSys raceSys) {
        List<RaceSys> list = raceSysService.selectRaceSysList(raceSys);
        ExcelUtil<RaceSys> util = new ExcelUtil<RaceSys>(RaceSys.class);
        util.exportExcel(response, list, "赛段信息数据");
    }

    /**
     * 获取赛段信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:query')")
    @GetMapping(value = "/{sectionName}")
    @Operation(summary = "获取赛段信息详细信息", description = "根据赛段名称获取赛段信息详细信息")
    public ResponseDTO<Object> getInfo(@PathVariable("sectionName") String sectionName) {
        return success(raceSysService.selectRaceSysBySectionName(sectionName));
    }

    /**
     * 新增赛段信息
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:add')")
    @Log(title = "赛段信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增赛段信息", description = "新增赛段信息")
    public ResponseDTO<Object>add(@RequestBody RaceSys raceSys) {
        return toAjax(raceSysService.insertRaceSys(raceSys));
    }

    /**
     * 修改赛段信息
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:edit')")
    @Log(title = "赛段信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改赛段信息", description = "修改赛段信息")
    public ResponseDTO<Object>edit(@RequestBody RaceSys raceSys) {
        return toAjax(raceSysService.updateRaceSys(raceSys));
    }

    /**
     * 删除赛段信息
     */
    @PreAuthorize("@ss.hasPermi('RaceSys:raceInfo:remove')")
    @Log(title = "赛段信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sectionNames}")
    @Operation(summary = "删除赛段信息", description = "删除赛段信息")
    public ResponseDTO<Object>remove(@PathVariable String[] sectionNames) {
        return toAjax(raceSysService.deleteRaceSysBySectionNames(sectionNames));
    }


    // RaceInfoController.java

    @GetMapping("/listAllSaishi")
    public ResponseDTO<Object> listAllSaishi() {
        return AjaxResult.success(raceSysService.selectAllSaishi());
    }
}
